package com.cskaoyan.controller.wxcontroller;

import com.cskaoyan.bean.pojo.Topic;
import com.cskaoyan.bean.vo.BaseRespVo;
import com.cskaoyan.beanwx.bo.WxBaseParam;
import com.cskaoyan.beanwx.vo.TopicDetailVO;
import com.cskaoyan.beanwx.vo.TopicListVO;
import com.cskaoyan.exception.ObtainDataFailException;
import com.cskaoyan.service.TopicService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("wx/topic")
@SuppressWarnings("all")
/**
 * @description: topic专题部分
 * @author: liusenbiao
 * @creatTime: 2021年07月12日
 */

public class WxTopicController {
    @Autowired
    TopicService topicService;
    @RequestMapping("list")
    public BaseRespVo getListByPageAndSize(WxBaseParam param) {
        TopicListVO listVO = topicService.queryTopicListByPageAndSize(param);
        return BaseRespVo.ok(listVO);
    }
    @GetMapping("detail")
    public BaseRespVo topicDetail(Integer id) throws ObtainDataFailException {
        TopicDetailVO topicDetail;
        try {
            topicDetail = topicService.getTopicDetail(id);
        } catch (Exception e) {
            e.printStackTrace();
            throw new ObtainDataFailException("获取信息失败");
        }
        return BaseRespVo.ok(topicDetail);
    }


    @GetMapping("related")
    public BaseRespVo topicRelated(Integer id) throws ObtainDataFailException {
        List<Topic> topics;
        try {
            topics = topicService.getRelatedTopics(id);
        } catch (Exception e) {
            e.printStackTrace();
            throw new ObtainDataFailException("获取信息失败");
        }
        return BaseRespVo.ok(topics);
    }
}
